Socket
Socket
Sign inDemoInstall

json-rpc-engine

Package Overview
Dependencies
Maintainers
6
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-rpc-engine

A tool for processing JSON-RPC messages.


Version published
Weekly downloads
134K
decreased by-63.28%
Maintainers
6
Weekly downloads
 
Created

What is json-rpc-engine?

The json-rpc-engine npm package is a JavaScript library that provides a framework for building JSON-RPC 2.0 servers and clients. It allows you to create middleware stacks to handle JSON-RPC requests and responses, making it easier to manage and extend your JSON-RPC services.

What are json-rpc-engine's main functionalities?

Creating a JSON-RPC Engine

This feature allows you to create a new JSON-RPC engine instance, which serves as the core component for handling JSON-RPC requests and responses.

const { JsonRpcEngine } = require('json-rpc-engine');
const engine = new JsonRpcEngine();

Adding Middleware

You can add middleware to the JSON-RPC engine to handle specific methods or perform actions before passing the request to the next middleware. In this example, a middleware is added to handle the 'hello' method.

engine.push((req, res, next, end) => {
  if (req.method === 'hello') {
    res.result = 'world';
    return end();
  }
  next();
});

Handling Requests

This feature demonstrates how to handle a JSON-RPC request using the engine. The request is processed through the middleware stack, and the response is returned via a callback function.

const request = { jsonrpc: '2.0', method: 'hello', id: 1 };
engine.handle(request, (err, res) => {
  if (err) {
    console.error(err);
  } else {
    console.log(res);
  }
});

Other packages similar to json-rpc-engine

FAQs

Package last updated on 20 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc